Skip to content

GPU: make the Metal atomics operate on plain counters - #15944

Open
ktf wants to merge 1 commit into
AliceO2Group:devfrom
ktf:pr15944
Open

ktf wants to merge 1 commit into
AliceO2Group:devfrom
ktf:pr15944

Conversation

@ktf

@ktf ktf commented Oct 12, 2026

Copy link
Copy Markdown
Member

GPUAtomic() expanded to metal::atomic, but the counters it guards are plain
integers in structures that the host allocates and transfers, and the code reads
them directly outside the atomic operations. That is exactly the CUDA and HIP
situation, where GPUAtomic() is a no-op and atomicAdd() takes a plain pointer,
so Metal now does the same.

MSL's atomic_explicit do want metal::atomic, which has the same size and
alignment, so the operand is cast at the one point where the operation is
issued. The cast has to keep the address space, which a generic pointer does not
carry into atomic
_explicit, hence the two overloads: threadgroup stays
threadgroup for the *Shared entry points, anything else resolves to device.

GPUTPCCFDecodeZS's shared memory had to be declared GPUsharedref() for that to
hold; without it the reference is generic by the time AtomicAddShared sees it.

GPUAtomic() expanded to metal::atomic, but the counters it guards are plain
integers in structures that the host allocates and transfers, and the code reads
them directly outside the atomic operations. That is exactly the CUDA and HIP
situation, where GPUAtomic() is a no-op and atomicAdd() takes a plain pointer,
so Metal now does the same.

MSL's atomic_*_explicit do want metal::atomic, which has the same size and
alignment, so the operand is cast at the one point where the operation is
issued. The cast has to keep the address space, which a generic pointer does not
carry into atomic_*_explicit, hence the two overloads: threadgroup stays
threadgroup for the *Shared entry points, anything else resolves to device.

GPUTPCCFDecodeZS's shared memory had to be declared GPUsharedref() for that to
hold; without it the reference is generic by the time AtomicAddShared sees it.
@ktf
ktf requested a review from davidrohr as a code owner October 12, 2026 13:24

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant